//
//  Albums.swift
//  lookLikeIweekly
//
//  Created by Mainzxq on 16/6/7.
//  Copyright © 2016年 Mainzxq. All rights reserved.
//

import Foundation
import Photos

var myAssets = PHFetchResult()
var myselect = [PHAsset]()
var imageArray = [UIImage]()


func getPHAssetResult() -> PHFetchResult {
    let allOptions = PHFetchOptions()
    allOptions.sortDescriptors = [NSSortDescriptor.init(key: "creationDate", ascending: true)]
    let allResults = PHAsset.fetchAssetsWithOptions(allOptions)
    return allResults
}


func getAssetArray(result: PHFetchResult) -> [PHAsset] {
    var tempArray = [PHAsset]()
    for idx in 0...result.count-1 {
        tempArray.append(result[idx] as! PHAsset)
    }
    return tempArray
}


func getImageArray(AssetArray:[PHAsset]) -> [UIImage]{
    imageArray = [UIImage]()
    let cacheOption = PHImageRequestOptions()
    cacheOption.synchronous = true
    cacheOption.deliveryMode = .HighQualityFormat
    cacheOption.resizeMode = .Fast
    for item in AssetArray {
        PHCachingImageManager.defaultManager().requestImageForAsset(item , targetSize: CGSize(width: 600,height: 600), contentMode: .AspectFit, options: cacheOption) { (result: UIImage?, dictionry: Dictionary?) in
            imageArray.append(result!)
        }
    }
    return imageArray
}